/*
 * @lc app=leetcode.cn id=96 lang=javascript
 *
 * [96] 不同的二叉搜索树
 */

// @lc code=start
/**
 * @param {number} n
 * @return {number}
 */
var numTrees = function (n) {
  let dp = [];
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;

  for (let i = 3; i <= n; i++) {
    let z = i - 1;
    let sum = 0;
    for (let s = 0; s <= z; s++) {
      sum += dp[s] * dp[z - s];
    }

    dp[i] = sum;
  }

  return dp[n];
};

const res = numTrees(4);
// @lc code=end
